package com.coding.controller;

import com.coding.base.pojo.BaseModel;
import com.coding.pojo.Task;
import com.coding.service.TaskService;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @auther wangchenghao
 * @date 2020/7/27
 **/

@Controller
@ResponseBody
@RequestMapping("task")
public class TaskController {
    @Autowired
    TaskService taskService;

    @ApiOperation("查询任务，可增加条件")
    @RequestMapping(value = "/getPageList", method = {RequestMethod.GET})
    public BaseModel getResList(@ApiParam("任务资源类型") @RequestParam(value = "task_kind", required = false) String task_kind,
                                @ApiParam("任务名字") @RequestParam(value = "task_name", required = false) String task_name,
                                @ApiParam("任务tag") @RequestParam(value = "task_tag", required = false) String task_tag,
                                @ApiParam("任务更多") @RequestParam(value = "task_more1", required = false) String task_more1
    ) throws Exception {
        BaseModel model = new BaseModel();
        Task task = new Task();
        task.setTask_kind(task_kind);
        task.setTask_name(task_name);
        task.setTask_tag(task_tag);
        task.setTask_more1(task_more1);
        taskService.gettasklist(task, model);
        return model;
    }

    @ApiOperation("通过id查询任务")
    @RequestMapping(value = "/getById", method = {RequestMethod.GET})
    public BaseModel getbyid(@ApiParam("任务id") @RequestParam(value = "task_id", required = true) int task_id
    ) throws Exception {
        BaseModel model = new BaseModel();
        taskService.gettaskbyid(task_id,model);
        return model;
    }

    @ApiOperation("获得基础任务栏")
    @RequestMapping(value = "/getBasicList", method = {RequestMethod.GET})
    public BaseModel getbasicList() throws Exception {
        BaseModel model = new BaseModel();
        Task task = new Task();
        task.setTask_tag("new");
        taskService.gettasklist(task, model);
        return model;
    }

    @ApiOperation("新创任务")
    @RequestMapping(value = "/insertNewTask", method = {RequestMethod.POST})
    public BaseModel insertnewtask(@ApiParam("任务资源id") @RequestParam(value = "task_source_id", required = false) Integer task_source_id,
                                  @ApiParam("任务资源类型kind") @RequestParam(value = "task_kind", required = false) String task_kind,
                                  @ApiParam("任务name") @RequestParam(value = "task_name", required = true) String task_name,
                                  @ApiParam("任务tag") @RequestParam(value = "task_tag", required = true) String task_tag,
                                  @ApiParam("任务积分point") @RequestParam(value = "task_point", required = true) Integer task_point,
                                  @ApiParam("任务more1") @RequestParam(value = "task_more1", required = false) String task_more1) throws Exception {
        BaseModel model = new BaseModel();
        Task task = new Task();
        task.setTask_source_id(task_source_id);
        task.setTask_kind(task_kind);
        task.setTask_name(task_name);
        task.setTask_tag(task_tag);
        task.setTask_point(task_point);
        task.setTask_more1(task_more1);
        taskService.addnewlist(task,model);

        return model;
    }
}
